package collections;

import java.util.Iterator;
import java.util.LinkedList;



public class TestLinkedList {

	
	public static void main(String[] args) {
	LinkedList<String> ll=new LinkedList<String>();
	ll.add("B");
	ll.add("C");
	ll.addFirst("A");
	ll.addLast("D");
	System.out.println("Size :"+ll.size());
	Iterator<String> it=ll.iterator();
	while(it.hasNext()){
		System.out.print(" "+it.next());
        it.remove();	
       }
	System.out.println("\nAfter remove() of iterator");
	System.out.println("\nSize :"+ll.size());

   ll.add("sai");
   ll.add("ram");
   ll.add(null);   
   ll.add(1,"Krishna");   
	   System.out.println("After adding  elements and a null..");
	   System.out.println("Size :"+ll.size());
	   System.out.println(ll);          //toString() called.
	   System.out.println(ll.poll());
	   System.out.println(ll);
	   System.out.println(ll.peek());   //poll() and peek()
	   System.out.println(ll);
	
	}

}












/*The difference between addFirst() and offerFirst() is that the add method 
 * will throw an exception should the adding of the item fail
 *  but the offer() method will simply return false
*/